﻿using System;

namespace Microsoft.Xna.Framework.Content
{
	/// <summary>
	/// A custom Attribute that marks a field or property to control how it is serialized or to indicate that protected or private data should be included in serialization.
	/// </summary>
	[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
	public sealed class ContentSerializerAttribute : Attribute
	{
		#region Properties
		/// <summary>
		/// Get or set a value indicating whether this member can have a null value (default=true).
		/// </summary>
		public bool AllowNull { get; set; }

		/// <summary>
		/// Gets or sets the XML element name for each item in a collection (default = "Item").
		/// </summary>
		public string CollectionItemName { get; set; }

		/// <summary>
		/// Gets or sets the XML element name (default=name of the managed type member).
		/// </summary>
		public string ElementName { get; set; }

		/// <summary>
		/// Gets or sets a value idicating whether to write member contents directly into the current XML context rather than wrapping the member in a new XML element (default=false).
		/// </summary>
		public bool FlattenContent { get; set; }

		/// <summary>
		/// Indicates whether an explicit CollectionItemName string is being used or the default value.
		/// </summary>
		public bool HasCollectionItemName
		{
			get { return !String.IsNullOrEmpty(CollectionItemName); }
		}

		/// <summary>
		/// Indicates whether to write this element if the member is null and skip past it if not found when deserializing XML (default=false).
		/// </summary>
		public bool Optional { get; set; }

		/// <summary>
		/// Indicates whether this member is referenced from multiple parents and should be serialized as a unique ID reference (default=false).
		/// </summary>
		public bool SharedResource { get; set; }
		#endregion

		/// <summary>
		/// Creates a new instance of ContentSerializerAttribute.
		/// </summary>
		public ContentSerializerAttribute()
		{
		}

		/// <summary>
		/// Creates a copy of the ContentSerializerAttribute.
		/// </summary>
		public ContentSerializerAttribute Clone()
		{
			ContentSerializerAttribute csa = new ContentSerializerAttribute();
			csa.AllowNull = this.AllowNull;
			csa.CollectionItemName = this.CollectionItemName;
			csa.ElementName = this.ElementName;
			csa.FlattenContent = this.FlattenContent;
			csa.Optional = this.Optional;
			csa.SharedResource = this.SharedResource;
			return csa;
		}
	}
}
